package com.lzq.util;


import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class UnsafeInstance {

    //获取Unsafe对象
    public static Unsafe reflectGetUnsafe() {

        //通过反射机制获取到Unsafe类
        Field field = null;
        try {
            field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            return (Unsafe) field.get(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}